Attribute VB_Name = "modTime"
Option Explicit

Public Declare Function timeGetTime Lib "winmm.dll" () As Long  'timeGetTimeVB
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Public Function timeGetTimeVB() As Double
    Dim lRawTime As Long
    Dim dblTemp As Double

    lRawTime = timeGetTime()    'timeGetTimeVB
    If (lRawTime < 0) Then      'convert to unsigned integer
        dblTemp = (CDbl(lRawTime) + 1#) + 4294967295#
    Else
        dblTemp = lRawTime
    End If
    timeGetTimeVB = dblTemp
End Function

Public Function msTimeExpired(curStartTimeMS As Currency, curDelayTimeMS As Currency) As Boolean
    Dim curNewTime As Currency
    curNewTime = timeGetTimeVB()
    If curStartTimeMS < 0 Then curStartTimeMS = curStartTimeMS + CCur(2 ^ 32)
    If ((curNewTime < 0) Or (curNewTime < curStartTimeMS)) Then
        curNewTime = curNewTime + CCur(2 ^ 32)
    End If
    msTimeExpired = CBool(curNewTime >= (curStartTimeMS + curDelayTimeMS))
End Function

Public Function msTimeStart() As Currency
    Dim curNewTime As Currency
    msTimeStart = timeGetTimeVB()
End Function

Public Function msTimeDiff(curStartTime As Currency) As Currency
    Dim curNewTime As Currency
    curNewTime = timeGetTimeVB()
    If (curNewTime < curStartTime) Then
        curStartTime = curStartTime
        curNewTime = curNewTime + (2 ^ 32)
        msTimeDiff = curNewTime - curStartTime
    Else
        msTimeDiff = curNewTime - curStartTime
    End If
End Function

Public Function msDelay(MSec As Long) As Boolean
    Dim curStart As Currency
    Dim TimeExpired As Boolean
    Dim i As Long
    TimeExpired = False
    curStart = msTimeStart()
    Do
        DoEvents
        TimeExpired = msTimeExpired(curStart, CCur(MSec))
    Loop While (Not TimeExpired)
    msDelay = TimeExpired
End Function


